<template>
	<view class="container">
		<view class="title">家长通讯录</view>
		<view class="list-box">
			
			<view class="item-box" v-for="(item,index) in parentList" :key="item.Id">
				<view class="img-box">
					<image src="https://public-1300796766.cos.ap-guangzhou.myqcloud.com/mini/1.jpg" class="img"></image>
				</view>
				<view class="content-box">
					<view class="name">姓名：{{item.RealName}}</view>
					<view class="mobile">电话：{{item.Phone}}</view>
				</view>
			</view>
			
			<view class="loading" v-show="isShowLoading">
				<image class="loading-img" src="../../static/img/loading.gif"></image>
			</view>
			<view class="no-more" v-show="isShowNoMore">家长就这么多了</view>
			
		</view>
	</view>
</template>

<script>
	import {myRequest} from '../../utils'
	
	export default {
		data() {
			return {
				isShowList: true,
				isLoading: false,
				currentPage: 1,
				isShowLoading: false,
				isShowNoMore: false,
				parentList: [],
				timer: null,
			}
		},
		
		onShow() {
			this.fetchData()
		},
		
		onReachBottom() {
			let that = this
			that.fetchData()
		},
		
		methods: {
			
			fetchData() {
				let that = this
				if (that.isShowNoMore || that.isLoading) return
				that.isLoading = true
				that.isShowLoading = true
				
				if(that.timer != null){
					clearTimeout(that.timer);
				}
				
				that.timer = setTimeout(function(){
					
					myRequest({
						url: '/api/user/parent_book',
						data: {
							p: that.currentPage
						},
					}, function(res) {
						that.isLoading = false
						that.isShowLoading = false
						
						if (res.statusCode != 200) {
							that.isShowList = false
							uni.showModal({
								title: '提示',
								content: '服务器错误，请求失败'
							})
							return
						}
						
						if (res.data.status != 0) {
							uni.navigateTo({
								url: '/pages/login/login'
							})
							return
						}
						
						let dataList = res.data.data
						if (that.currentPage > 1 && dataList.length <= 0) {
							that.isShowNoMore = true
							return
						}
						
						that.currentPage++
						that.parentList = that.parentList.concat(dataList)
					})
					
				}, 1000);
				
			}
			
		}
	}
</script>

<style>
	.container {
	  width: 750rpx;
	  height: auto;
	  background-image: linear-gradient(#ffae00, #eee, #efefef);
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  padding-bottom: 160rpx;
	  min-height: 1800rpx;
	}
	
	.title {
		width: 66%;
		height: 100rpx;
		display: flex;
		align-items: center;
		font-size: 48rpx;
	}
	
	.list-box {
		width: 550rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	
	.item-box {
		display: flex;
		align-items: center;
		position: relative;
		width: 100%;
		height: 160rpx;
	}
	
	.img-box {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		background-color: #ffffff;
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		z-index: 100;
	}
	
	.img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}
	
	.content-box {
		font-size: 26rpx;
		display: flex;
		align-items: center;
		height: 100rpx;
		background-color: #ffffff;
		border-radius: 32rpx;
		box-shadow: 6rpx 4rpx 18rpx 0rpx rgba(145, 124, 24, 0.49);
		z-index: 99;
		width: 100%;
		padding-right: 20rpx;
		margin-left: 50rpx;
	}
	
	.name {
		width: 180rpx;
	}
	
	.loading {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 30rpx;
		background-color: #ffffff;
	}
	
	.loading-img {
		width: 200rpx;
		height: 150rpx;
	}
	
	.no-more {
		padding-top: 40rpx;
		padding-bottom: 20rpx;
		font-size: 28rpx;
		color: #666666;
	}
</style>
